package com.hellobike.haxing.web.shop;

import com.hellobike.haxing.order.api.IOrderStatsService;
import com.hellobike.haxing.order.model.request.ShopDistributionPageRequest;
import com.hellobike.haxing.order.model.vo.PromoterStaticsVo;
import com.hellobike.haxing.order.model.vo.ShopDistributionStatsVo;
import com.hellobike.haxing.order.result.PageResult;
import com.hellobike.haxing.order.result.Result;
import com.hellobike.haxing.request.shop.ShopIdRequest;
import com.hellobike.haxing.user.vo.SmallShopVo;
import com.hellobike.haxing.util.UserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "推广员主管接口")
@RestController
@RequestMapping(value = "/promoter")
@Slf4j
public class PromoterController {

    @Autowired
    private UserUtil userUtil;

    @Reference(version = "1.0.0")
    private IOrderStatsService orderStatsService;

    @ApiOperation("我的分销统d计数据")
    @PostMapping(value = "/stats")
    public Result<PromoterStaticsVo> distributionStats() {
        SmallShopVo smallShopVo = userUtil.getUser().getShopVo();
        PromoterStaticsVo promoterStaticsVo = orderStatsService
                .promoterStats(smallShopVo.getId(),smallShopVo.getShopType());
        return Result.ok(promoterStaticsVo);
    }

    @ApiOperation("我的团员发展的店铺信息")
    @PostMapping(value = "/shop-stats")
    public PageResult<ShopDistributionStatsVo> shopDistributionStats(@RequestBody ShopIdRequest request) {
        ShopDistributionPageRequest shopDistributionPageRequest = new ShopDistributionPageRequest();
        shopDistributionPageRequest.setShopId(request.getShopId());
        shopDistributionPageRequest.setSelfId(userUtil.getUser().getShopVo().getId());
        shopDistributionPageRequest.setCurPage(request.getCurPage());
        shopDistributionPageRequest.setPageSize(request.getPageSize());
        return orderStatsService.promoterDetail(shopDistributionPageRequest);
    }

    @ApiOperation("我的发展推广员业绩")
    @PostMapping(value = "/promoter-list")
    public PageResult<PromoterStaticsVo> promoterList(@RequestBody ShopIdRequest request) {
        log.info("推广收益");
        ShopDistributionPageRequest shopDistributionPageRequest = new ShopDistributionPageRequest();
        shopDistributionPageRequest.setShopId(userUtil.getUser().getShopVo().getId());
        shopDistributionPageRequest.setSelfId(userUtil.getUser().getShopVo().getId());
        shopDistributionPageRequest.setCurPage(request.getCurPage());
        shopDistributionPageRequest.setPageSize(request.getPageSize());
        return orderStatsService.promoterList(shopDistributionPageRequest);
    }
}
